﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SportsPlatform.Application.Dto.SportBusiness.CompetitionProjec;
using SportsPlatform.Application.Query.CompetitionProjec;
using SportsPlatform.Base;
using SportsPlatform.Dto.SportBusiness.CompetitionProjec;
using SportsPlatform.Dto.SportBusiness.EventsSession;
using SportsPlatform.Filters;
using SportsPlatform.Query.CompetitionProjec;
using SportsPlatform.SportBusiness.ISportBusiness;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SportsPlatform.Controllers
{
    /// <summary>
    /// 赛事项目控制器
    /// </summary>

    [ActionAuthorization]
    [Route("api/[controller]/[action]")]
    public class CompetitionProjectController : SportsPlatformControllerBase
    {
        private ICompetitionProjectService _service;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="service"></param>
        public CompetitionProjectController(ICompetitionProjectService service)
        {
            _service = service;
        }

        /// <summary>
        /// 分页获取赛事比赛项目列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PagePagingDto<GetCompetitionProjecListDto>> GetCompetitionProjecList([FromBody] GetCompetitionProjecListQuery query)
        {
            return await _service.GetCompetitionProjecList(query);
        }

        /// <summary>
        /// 根据赛事ID获取当前赛事状态为正在报名到比赛结束之前的赛事项目列表
        /// 用于添加报名时根据赛事ID获取
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultListDto<GetComProjectListByComIdDto>> GetComProjectListByComId([FromBody] GetComProjectListByComIdQuery query)
        {
            return await _service.GetComProjectListByComId(query);
        }

        /// <summary>
        /// 获取当前比赛项目
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultListDto<GetCurrentCompetitionProjectListDto>> GetCurrentCompetitionProjectList()
        {
            return await _service.GetCurrentCompetitionProjectList();
        }

        /// <summary>
        /// 新增、修改赛事比赛项目
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseResultDto> EditCompetitionProjec([FromBody] EditCompetitionProjecQuery query)
        {
            return await _service.EditCompetitionProjec(query);
        }

        /// <summary>
        /// 结束报名
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseResultDto> EndSignUp([FromBody] CompetitionProjectIdQuery query)
        {
            return await _service.EndSignUp(query);
        }

        /// <summary>
        /// 结束赛事项目
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseResultDto> EndCompetitionProject([FromBody] CompetitionProjectIdQuery query)
        {
            return await _service.EndCompetitionProject(query);
        }

        /// <summary>
        /// 启用比赛项目
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseResultDto> EnableCompetitionProject([FromBody] CompetitionProjectIdQuery query)
        {
            return await _service.EnableCompetitionProject(query);
        }

        /// <summary>
        /// 关闭比赛项目
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseResultDto> CloseCompetitionProject([FromBody] CompetitionProjectIdQuery query)
        {
            return await _service.CloseCompetitionProject(query);
        }

        /// <summary>
        /// 根据比赛项目Id获取比赛项目详情
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultDto<GetCompetitionPorjectDetailsDto>> GetCompetitionPorjectDetailsById([FromBody] CompetitionProjectIdQuery query)
        {
            return await _service.GetCompetitionPorjectDetailsById(query);
        }

        /// <summary>
        /// 获取比赛规则
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultListDto<GetRuleListDto>> GetRuleList([FromBody] GetRuleListQuery query)
        {
            return await _service.GetRuleList(query);
        }

        /// <summary>
        /// 获取比赛分组报名人员列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymousAttribute]
        public async Task<ResultListDto<GetGroupListDto>> GetGroupList([FromBody] GetGroupListQuery query)
        {
            return await _service.GetGroupList(query);
        }

        /// <summary>
        /// 根据赛事项目ID获取最大报名人数限制和是否达到最大报名人数限制
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultDto<GetMaxEmployeeNumDto>> GetMaxEmployeeNum([FromBody] GetMaxEmployeeNumQuery query)
        {
            return await _service.GetMaxEmployeeNum(query);
        }

        /// <summary>
        /// 客户端分页获取赛事项目信息（用于信息同步）
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PagePagingDto<GetPageCompetitionPorjectKHDDto>> GetPageCompetitionPorjectKHD([FromBody]BasePageQuery query)
        {
            return await _service.GetPageCompetitionPorjectKHD(query);
        }

        /// <summary>
        /// 客户端赛事项目信息同步
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseResultDto> CompetitionPorjectSynchronization([FromBody] List<CompetitionPorjectSynchronizationQuery> query)
        {
            return await _service.CompetitionPorjectSynchronization(query);
        }
    }
}
